import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    meta: { title: '后台管理', icon: 'dashboard' },
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页', icon: 'dashboard' }
      },
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/category/index'),
        meta: { title: '模板分类', icon: 'dashboard' }
      },
      {
        path: 'material',
        name: 'material',
        component: () => import('@/views/material/index'),
        meta: { title: '模板内容', icon: 'dashboard' }
      },
      {
        path: 'productDesc',
        name: 'productDesc',
        component: () => import('@/views/productDesc/index'),
        meta: { title: '产品介绍', icon: 'dashboard' }
      },
      {
        path: 'content',
        name: 'content',
        component: () => import('@/views/content/index'),
        meta: { title: '交流设计', icon: 'dashboard' }
      },
      {
        path: 'news',
        name: 'news',
        component: () => import('@/views/news/index'),
        meta: { title: '推广专区', icon: 'dashboard' }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/index'),
        meta: { title: '注册用户', icon: 'dashboard' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
